/*
--------------------------------------------------------------------------------------------------------------------
Copyright (c) 2009, Brian Delgado
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Portland State University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------------------------------------
  Brian Delgado, brian.delgado [at] gmail.[com]
  Nelson Ijih, neliji[at]gmail.[com]
  Taibat Onaolapo Morakinyo, tomorakinyo[at]gmail.[com]

*/
#include <fstream.h>

#define MAX_FILE_NAME_LENGTH 255
#define NO_CHILD -1
#define INVALID -1
#define NUM_THREADS 4
#define ENABLED 1

#define PARALLEL 0
#define SEQEXACT 1
#define PARTIAL 2
#define FROMFILE 3
#define INTERACTIVE 4
#define PRINT_TREE 5

void*  master  (void * arg);
int buildTree(int max_size, unsigned int &uniquenodes, unsigned int *reused_nodes, struct node *head, char *filename, unsigned int verbose);
void* worker (void*);
int initNode(struct node *&thisnode); // Init a node with default values
struct node* insertTree(char *insertString, struct node *&head, int location, unsigned int &uniquenodes, unsigned int *reused_nodes, unsigned int verbose, unsigned int &added); // Put a node into a tree
int printTree(struct node*&head, char ch, int level, char *printout, unsigned int matchlen, ofstream &ofs, int file_io);
int partial_searchTree(struct node*&head, int level, char *searchstring, int start, int end,unsigned int matchlen);
int par_searchTree(struct node*&head, int level, char *searchstring, unsigned int matchlen, struct matchList_str *&RetMatchPtr);
int seq_searchTree(struct node*&head, int level, char *searchstring, unsigned int matchLen);
int MakeStringPermutations(char *origString, char *reversed, char *flipped, char *flippedreversed);
char *subString(char *aString,int start,int end);
int seqExactMatch(char *searchstring, struct node *head);
int searchInput_inFile(struct node *head, unsigned int MATCH_SIZE);
int partialMatchSearch(char *searchstring, int start, int end, struct node *head, char *inname, unsigned int verbose);
int parallelSearch(char *searchstring, struct node*head);
int detectMatchSize_inFile();
int interactive( struct node *head, unsigned int length);
int check_arg(int argnum, int num_args);


// This node gets placed in the tree
struct node {
  struct node* anext;
  struct node* cnext;
  struct node* gnext;
  struct node* tnext;
  struct matchList_str* matchList;
};


struct matchList_str  {
  int matchposition;
 struct  matchList_str* next;
};

// Parallel search structure
struct node_t
{
  int id;
  int noproc;
  int i;      //level
  int found;
  char *k;    //search string
  int cur;
  struct node* head;
  struct matchList_str *matchPtr;
};

